﻿<%@ Page CodeFileBaseClass="AliCMS.Lib.SystemPageBase" %>
<script language="c#" runat="server">
protected string Condition()
{
	StringBuilder condition = new StringBuilder();
	string and = String.Empty;

	#region 是否付款
	string isPayed = Request.QueryString["IsPayed"];
	if (!String.IsNullOrEmpty(isPayed))
		condition.Append(and + Alias.Order.IsPayed + "=" + isPayed);
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 是否发货
	string isDelivered = Request.QueryString["IsDelivered"];
	if (!String.IsNullOrEmpty(isDelivered))
		condition.Append(and + Alias.Order.IsDelivered + "=" + isDelivered);
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 是否完成
	string isFinished = Request.QueryString["IsFinished"];
	if (!String.IsNullOrEmpty(isFinished))
		condition.Append(and + Alias.Order.IsFinished + "=" + isFinished);
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 是否作废
	string isCanceled = Request.QueryString["IsCanceled"];
	if (!String.IsNullOrEmpty(isCanceled))
		condition.Append(and + Alias.Order.IsCanceled + "=" + isCanceled);
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 是否归档
	string isArchived = Request.QueryString["IsArchived"];
	if (!String.IsNullOrEmpty(isArchived))
		condition.Append(and + Alias.Order.IsArchived + "=" + isArchived);
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 教师
	string teacherId = Request.QueryString["TeacherID"];
	if (!String.IsNullOrEmpty(teacherId))
		condition.Append(and + Alias.Order.TeacherID + "=" + teacherId);
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 关键词
	string keyword = Request.QueryString["Keyword"];
	if (!String.IsNullOrEmpty(keyword))
	{
		if (Request.QueryString["KeywordType"] == "All")
			condition.Append(and + "(" + Alias.Order.No + " LIKE '%" + keyword + "%' OR " + Alias.Order.CourseName + " LIKE '%" + keyword + "%' OR " + Alias.Order.UserName + " LIKE '%" + keyword + "%' OR " + Alias.Order.UserNickname + " LIKE '%" + keyword + "%' OR " + Alias.Order.DistributerName + " LIKE '%" + keyword + "%' OR " + Alias.Order.DistributerNickname + " LIKE '%" + keyword + "%' OR " + Alias.Order.TeacherName + " LIKE '%" + keyword + "%')");
		else if (Request.QueryString["KeywordType"] == "No")
			condition.Append(and + Alias.Order.No + "='" + keyword + "'");
		else if (Request.QueryString["KeywordType"] == "CourseName")
			condition.Append(and + Alias.Order.CourseName + "='" + keyword + "'");
		else if (Request.QueryString["KeywordType"] == "UserNickname")
			condition.Append(and + Alias.Order.UserNickname + "='" + keyword + "'");
		else if (Request.QueryString["KeywordType"] == "AgentNickname")
			condition.Append(and + Alias.Order.DistributerNickname + "='" + keyword + "'");
		else if (Request.QueryString["KeywordType"] == "TeacherName")
			condition.Append(and + Alias.Order.TeacherName + "='" + keyword + "'");
	}
	#endregion
	
	return condition.ToString();
}

protected string Sort()
{
	string sort = String.Empty;
	switch (Request.QueryString["Sort"])
	{
		case "1":
			sort = Alias.Order.InnerID + " DESC";
			break;
		case "2":
			sort = Alias.Order.InnerID + " ASC";
			break;
		default:
			sort = Alias.Order.InnerID + " DESC";
			break;
	}
	
	return sort;
}
</script>
<section data-page="order_list" data-title="订单管理" data-lang="<%=ContentLang%>">
	<dl class="path1">
		<dt><span>您的位置：</span>订单管理</dt>
		<dd>
			<select data-class="<%=ContentLang%>Font" data-ali-widget="combo">
				<ali:List Mark="System" Object="Language" Source="Manager.Languages">
					<ali:Record>
						<%If Convert.ToString(Ab) == ContentLang%>
							<option value="<%=Ab%>" selected><%=[AliCMS.SystemModule.Alias.Language.Name + PageLang]%></option>
						<%Else%>
							<option value="<%=Ab%>"><%=[AliCMS.SystemModule.Alias.Language.Name + PageLang]%></option>
						<%EndIf%>
					</ali:Record>
				</ali:List>
			</select>
		</dd>
	</dl>
	<div class="ali-tabs sub-nav" data-height-style="fill" data-event="click">
		<div class="ali-tabs-header">
			<div class="ali-tabs-nav-container">
				<ul>
					<li class="ali-active"><a>订单列表</a></li>
					<li><a href="stat.aspx?Lang=<%=ContentLang%>" target="ali-navtab">统计</a></li>
				</ul>
			</div>
		</div>
		<div class="ali-tabs-body">
			<div class="ali-tabs-panel">
				<form action="?Lang=<%=ContentLang%>" class="search1">
					<select name="IsPayed" data-ali-widget="combo">
						<option value="">是否付款</option>
						<option value="0">未付款</option>
						<option value="1">部分付款</option>
						<option value="2">已付款</option>
						<option value="3">部分退款</option>
						<option value="4">已退款</option>
					</select>
					<select name="IsDelivered" data-ali-widget="combo">
						<option value="">是否发货</option>
						<option value="0">未发货</option>
						<option value="2">已发货</option>
						<option value="3">已退货</option>
					</select>
					<select name="IsFinished" data-ali-widget="combo">
						<option value="">是否完成</option>
						<option value="false">未完成</option>
						<option value="true">已完成</option>
					</select>
					<select name="IsCanceled" data-ali-widget="combo">
						<option value="">是否取消</option>
						<option value="false">未取消</option>
						<option value="true">已取消</option>
					</select>
					<select name="IsArchived" data-ali-widget="combo">
						<option value="">是否归档</option>
						<option value="false">未归档</option>
						<option value="true">已归档</option>
					</select>
					<select name="TeacherID" data-ali-widget="combo">
						<option value="">所有教师</option>
						<ali:List ID="Teachers" Object="Teacher">
							<ali:Record>
								<option value="<%=ID%>"><%=Name%></option>
							</ali:Record>
						</ali:List>
					</select>
					<select name="Sort" class="ali-input" data-ali-widget="combo">
						<option value="1">编号↓</option>
						<option value="2">编号↑</option>
					</select>
					<input name="Keyword" class="ali-input <%=ContentLang%>Font">
					<select name="KeywordType"  class="ali-input" data-ali-widget="combo">
						<option value="All">全部</option>
						<option value="No">订单编号</option>
						<option value="CourseName">课程名称</option>
						<option value="UserNickname">用户昵称</option>
						<option value="AgentNickname">代理昵称</option>
						<option value="TeacherName">教师名称</option>
				</select>
					<button type="submit" class="ali-button">搜索</button>
				</form>
				<div class="content">
					<table data-ali-widget="grid" class="grid1" data-tree="true" data-root="">
						<thead>
							<tr>
								<th>订单编号</th>
								<th>课程名称</th>
								<th>下单日期</th>
								<th>订单总价</th>
								<th>用户名称</th>
								<th>代理名称</th>
								<th>代理佣金</th>
								<th>教师名称</th>
								<th>教师佣金</th>
								<th>订单状态</th>
								<th>订单操作</th>
							</tr>
						</thead>
						<tbody>
							<ali:List ID="List" Object="Order" Page="PageNumber" PageSize="20" Condition="Condition()" Sort="Sort()" Validate="True">
								<ali:Record>
									<tr data-id="<%=InnerID%>">
										<td><a href="view.aspx?Lang=<%=ContentLang%>&ID=<%=InnerID%>" target="ali-navtab"><%=No%></a></td>
										<td><a href="view.aspx?Lang=<%=ContentLang%>&ID=<%=InnerID%>" target="ali-navtab" class="<%=ContentLang%>Font"><%=CourseName%></a></td>
										<td class="CHSFont"><%=CreateTime%></td>
										<td class="CHSFont"><%=Convert.ToDecimal(Sum).ToString("0.00")%></td>
										<td class="CHSFont"><img src="<%=UserHead%>" style="vertical-align:middle" /><%=UserNickname%></td>
										<td>
											<%If !Convert.IsDBNull(DistributerID) && Convert.ToBoolean(DistributerIsAgent)%>
												<img src="<%=DistributerHead%>" style="vertical-align:middle" /><%=DistributerName%>
											<%EndIf%>
										</td>
										<td class="CHSFont"><%=Convert.ToDecimal(AgentCommision).ToString("0.00")%></td>
										<td>
											<%If !Convert.IsDBNull(TeacherID)%>
												<img src="<%=TeacherHead%>" style="vertical-align:middle" /><%=TeacherName%>
											<%EndIf%>
										</td>
										<td class="CHSFont"><%=Convert.ToDecimal(TeacherCommision).ToString("0.00")%></td>
										<td>
											<%If Convert.ToBoolean(IsArchived)%>
												已归档
											<%ElseIf Convert.ToBoolean(IsCanceled)%>
												已作废
											<%ElseIf Convert.ToBoolean(IsFinished)%>
												已完成
											<%Else%>
												<%If Convert.ToInt32(IsPayed) == 0%>
													未付款
												<%ElseIf Convert.ToInt32(IsPayed) == 1%>
													部分付款
												<%ElseIf Convert.ToInt32(IsPayed) == 2%>
													已付款
												<%ElseIf Convert.ToInt32(IsPayed) == 3%>
													部分退款
												<%ElseIf Convert.ToInt32(IsPayed) == 4%>
													已退款
												<%EndIf%>
												，
												<%If Convert.ToInt32(IsDelivered) == 0%>
													未发货
												<%ElseIf Convert.ToInt32(IsDelivered) == 1 || Convert.ToInt32(IsDelivered) == 2%>
													已发货<br>
													<%If Convert.IsDBNull(ExpiredTime)%>
														永不过期
													<%ElseIf Convert.ToDateTime(ExpiredTime) > DateTime.Now%>
														<%=Convert.ToDateTime(ExpiredTime).Subtract(DateTime.Now).Days%> 天后过期
													<%Else%>
														<%=DateTime.Now.Subtract(Convert.ToDateTime(ExpiredTime)).Days%> 天已过期
													<%EndIf%>													
												<%ElseIf Convert.ToInt32(IsDelivered) == 3%>
													已退货
												<%EndIf%>
											<%EndIf%>
										</td>
										<td>
											<%If Convert.ToBoolean(IsArchived) || Convert.ToBoolean(IsCanceled)%>
												<!-- 已归档或已取消 -->
												<a class="ali-button" data-operation="Delete">删除</a>
											<%ElseIf Convert.ToBoolean(IsFinished)%>
												<!-- 已完成 -->
												<a class="ali-button" data-operation="Archive">归档</a>
											<%Else%>
												<%If Convert.ToInt32(IsPayed) <= 1 && Convert.ToInt32(IsDelivered) == 0%>
													<!-- 未付款，未发货 -->
													<a class="ali-button" data-operation="Pay">付款</a><br>
													<a class="ali-button" data-operation="Deliver">发货</a><br>
													<a class="ali-button" data-operation="Cancel">取消</a><br>
												<%ElseIf Convert.ToInt32(IsPayed) <= 1 && Convert.ToInt32(IsDelivered) <= 2%>
													<!-- 未付款，已发货 -->
													<a class="ali-button" data-operation="Pay">付款</a><br>
													<a class="ali-button" data-operation="Return">退货</a><br>
													<a class="ali-button" data-operation="Archive">归档</a>
												<%ElseIf Convert.ToInt32(IsPayed) <= 1 && Convert.ToInt32(IsDelivered) == 3%>
													<!-- 未付款，已退货 -->
													<a class="ali-button" data-operation="Archive">归档</a>
												<%ElseIf Convert.ToInt32(IsPayed) == 2 && Convert.ToInt32(IsDelivered) == 0%>
													<!-- 已付款，未发货 -->
													<a class="ali-button" data-operation="Deliver">发货</a><br>
													<a class="ali-button" data-operation="Refund">退款</a><br>
													<a class="ali-button" data-operation="Archive">归档</a>
												<%ElseIf Convert.ToInt32(IsPayed) == 2 && Convert.ToInt32(IsDelivered) <= 2%>
													<!-- 已付款，已发货 -->
													<a class="ali-button" data-operation="Refund">退款</a><br>
													<a class="ali-button" data-operation="Return">退货</a>
													<%If Convert.IsDBNull(ExpiredTime) || Convert.ToDateTime(ExpiredTime) < DateTime.Now%>
														<br><a class="ali-button" data-operation="Finish">完成</a>
													<%EndIf%>
												<%ElseIf Convert.ToInt32(IsPayed) == 2 && Convert.ToInt32(IsDelivered) == 3%>
													<!-- 已付款，已退货 -->
													<a class="ali-button" data-operation="Refund">退款</a><br>
													<a class="ali-button" data-operation="Archive">归档</a>
												<%ElseIf Convert.ToInt32(IsPayed) >= 3 && Convert.ToInt32(IsDelivered) == 0%>
													<!-- 已退款，未发货 -->
													<a class="ali-button" data-operation="Archive">归档</a>
												<%ElseIf Convert.ToInt32(IsPayed) >= 3 && Convert.ToInt32(IsDelivered) <= 2%>
													<!-- 已退款，已发货 -->
													<a class="ali-button" data-operation="Return">退货</a><br>
													<a class="ali-button" data-operation="Archive">归档</a>
												<%ElseIf Convert.ToInt32(IsPayed) >= 3 && Convert.ToInt32(IsDelivered) == 3%>
													<!-- 已退款，已退货 -->
													<a class="ali-button" data-operation="Archive">归档</a>
												<%EndIf%>
											<%EndIf%>
										</td>
									</tr>
								</ali:Record>
							</ali:List>
						</tbody>
					</table>
					<ali:Pagination Page="PageNumber" PageSize="20" RecordCount="List[RecordCount]">
						<div class="pagination1" data-page-number="<%=PageNumber%>" data-page-count="<%=PageCount%>" data-page-size="<%=PageSize%>">
							<div class="pagination1-left">
								共<b><%=PageCount%></b>页，每页显示
									<select name="PageSize" data-ali-widget="combo">
										<option value="20">20</option>
										<option value="50">50</option>
										<option value="100">100</option>
										<option value="200">200</option>
									</select>条，共<b><%=RecordCount%></b>条记录
							</div>
							<ul class="pagination1-right">
								<ali:FirstPage>
									<ali:Yes>
										<li><span><span class="first disabled">首页</span></span></li>
										<li><span><span class="prev disabled">上一页</span></span></li>
									</ali:Yes>
									<ali:No>
										<li><a href="1"><span class="first">首页</span></a></li>
										<li><a href="<%=PageNumber - 1%>"><span class="prev">上一页</span></a></li>
									</ali:No>
								</ali:FirstPage>
								<ali:CurrentPage Range="5">
									<ali:Yes>
										<li class="active"><span><%=Index%></span></li>
									</ali:Yes>
									<ali:No>
										<li><a href="<%=Index%>"><%=Index%></a></li>
									</ali:No>
								</ali:CurrentPage>
								<ali:LastPage>
									<ali:Yes>
										<li><span><span class="next disabled">下一页</span></span></li>
										<li><span><span class="last disabled">末页</span></span></li>
									</ali:Yes>
									<ali:No>
										<li><a href="<%=PageNumber + 1%>"><span class="next">下一页</span></a></li>
										<li><a href="<%=PageCount%>"><span class="last">末页</span></a></li>
									</ali:No>
								</ali:LastPage>
			
								<li class="go">
									<input type="text" name="PageNumber" value="1" size="4"><button></button>
								</li>
							</ul>
						</div>
					</ali:Pagination>
				</div>
			</div>
		</div>
		<div class="ali-tabs-bottom"><b></b></div>
	</div>
</section>